<?php
/**
 * User: 呆呆
 * Agreement: 禁止使用本软件（系统）用于任何违法违规业务或项目,造成的任何法律后果允由使用者（或运营者）承担
 * Date: 2021/3/3
 * Time: 14:34
 */
namespace app\common\controller;
use think\Db;
use think\Controller;

class mq_gyzf extends Controller
{
    public function getReturn($code = 1, $data = "成功", $json = null)
    {
        return array("code" => $code, "data" => $data, "json" => $json);
    }
    
    public function cehsald($atad)//监控回调
    {
           return $this->getReturn(-1, '交易失败', $atad);
    }
    
    public function fukyem($data)//支付页面
    {
        $sz = Db::name("pay_sz")->find();
        $atad= Db::name("pay_gfg")->where("pid", $data['pid'])->where("mid", $data['mid'])->find();
        $user = Db::name("pay_user")->where("id", $data['pid'])->find();
        $data['timeOut'] = $user['bug_close'];//订单有效期
        return redirect($data['mid_url']);
    }
    
    public function exec($atad,$money,$type)
    {
        if($type =='alipay'){
            $type = 'alipay';
        }else if($type =='weixin'){
            $type = 'wxpay';
        }else if($type =='qq'){
            $type = 'qqpay';
        }
        $sz = Db::name("pay_sz")->find();
        $data = array(
		        "pid" => trim($atad['zhanghao']),//商户ID
		        "out_trade_no"	=> time(),//商户订单号
		        "type" => $type,//支付方式
		        "name"	=> "易支付",//商品名称
		        "money"	=> $money,//付款金额
		        "sitename"	=> $sz['web_name'],//网站名称
		        "notify_url" => http_type().url('pay/index/notify2'),//异步通知地址
		        "return_url" => http_type().url('pay/index/refer2'),//同步跳转地址
        );

        //建立请求
        ksort($data); //重新排序$data数组
        reset($data); //内部指针指向数组中的第一个元素
        $sign = ''; //初始化需要签名的字符为空
        $urls = ''; //初始化URL参数为空
        foreach ($data AS $key => $val) { //遍历需要传递的参数
            if ($val == ''||$key == 'sign') continue; //跳过这些不参数签名
            if ($sign != '') { //后面追加&拼接URL
                $sign .= "&";
                $urls .= "&";
            }
            $sign .= "$key=$val"; //拼接为url参数形式
            $urls .= "$key=" . $val; //拼接为url参数形式并URL编码参数值
        }
        $query = $urls . '&sign=' . efaz($data,$atad['ck']); //创建订单所需的参数
        $url = $atad['bf']."/submit.php?{$query}"; //支付页面
        $atad['data'] = $atad['zhanghao'].'|'.$atad['ck'].'|'.$atad['bf'];//通道监控数据
        $atad['pay_id']  = time();//通道订单号
        $atad['mid_url'] = $url;//通道二维码
        return $this->getReturn(1, $atad, $atad['data']);
    }
}